package com.sky.loveshop.service.impl;

import com.sky.loveshop.entity.ReceiveAddress;
import com.sky.loveshop.entity.qo.ReceiveAddressQO;
import com.sky.loveshop.mapper.ReceiveAddressMapper;
import com.sky.loveshop.service.ReceiveAddressService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * @author xcy
 * @version V1.0
 * @description
 * @date 2024/12/28 13:09
 */
@Slf4j
@Service
public class ReceiveAddressServiceImpl implements ReceiveAddressService {

    @Autowired
    private ReceiveAddressMapper receiveAddressMapper;

    @Override
    public int addReceiveAddress(ReceiveAddressQO qo) {
        ReceiveAddress address = new ReceiveAddress();
        BeanUtils.copyProperties(qo, address);
        return receiveAddressMapper.insert(address);
    }

    @Override
    public List<ReceiveAddress> getMyReceiveAddressList(Integer userId) {
        Example example1 = new Example(ReceiveAddress.class);
        example1.createCriteria().andEqualTo("userId", userId);
        List<ReceiveAddress> addressList = receiveAddressMapper.selectByExample(example1);
        return addressList;
    }

    @Override
    public int delReceiveAddressById(Integer id) {
        return receiveAddressMapper.deleteByPrimaryKey(id);
    }
}
